//check if two password are the same
var  password = document.getElementById('repw');
password.addEventListener('change', checkpassword, true);

function checkpassword(){
 var firstPassword = document.getElementById('pw').value;
 var secondPassword = document.getElementById('repw').value;
 
if (firstPassword != secondPassword){
alert("You must enter same password, please try again!");
document.getElementById('repw').value='';
document.getElementById('pw').value='';}}

//Check if the all field are filled 
 var conf = document.getElementById('confirm');
 conf.addEventListener('click',checkEmpty,true);
 
function checkEmpty(){
if (
 ( !document.getElementById('oldpassword').value ) ||  
 (	!document.getElementById('pw').value) || 
 (	!document.getElementById('repw').value) 
 )
 	alert ("You must fill all information!");
 else {
 if (confirm("Are you sure your want to submit?")){
  alert("Change password succeeded!");
  window.location = "view.html";
 }
 }
}

//clear all field
var clear = document.getElementById('clear');
clear.addEventListener('click', clearfield, true);

function clearfield(){
    document.getElementById('oldpassword').value   = '';
	document.getElementById('pw').value            = '';
    document.getElementById('repw').value          = '';
}


